package com.tms.test;

import com.zebra.remoting.connection.DefaultConnectionFactory;
import com.zebra.remoting.protocol.CommandModelManager;
import com.zebra.register.RegisterHeartHandler;
import com.zebra.remoting.protocol.ZebraCodec;
import io.netty.channel.Channel;

public class TmsClient {


   private DefaultConnectionFactory connectionFactory;
    static String  addr  = "127.0.0.1";
    static int port = 8989;

    public TmsClient() {
        // 1. create a rpc client
        connectionFactory = new DefaultConnectionFactory();
        connectionFactory.registerCommandHandler(new TmsClientCommandHandler());
        connectionFactory.registerRpcCodec(new ZebraCodec());
        connectionFactory.registerHeartbeatProcessor(new RegisterHeartHandler());
    }

    public static void main(String[] args) throws Exception {
        CommandModelManager.initializeCommandCode(TestCommandCode.getMap());
        TmsClient client = new TmsClient();
        client.connectionFactory.init();
        Channel channel = client.connectionFactory.connect(addr, port, 3000);
//        Channel channel2 = client.connectionFactory.connect(addr, port, 3000);
       /* try {
            String res = (String) client.invokeSync(addr, req, 3000);
            TimeUnit.MILLISECONDS.sleep(5000);
            System.out.println("invoke sync result = [" + res + "]");
        } catch (RemotingException e) {
            String errMsg = "RemotingException caught in oneway!";
            logger.error(errMsg, e);
            Assert.fail(errMsg);
        } catch (InterruptedException e) {
            logger.error("interrupted!");
        }
        client.shutdown();*/
    }
}
